package com.test.spi;

import com.test.protocol.messages.ConnectMessage;
import com.test.protocol.messages.PubAckMessage;
import com.test.protocol.messages.PubCompMessage;
import com.test.protocol.messages.PubRecMessage;
import com.test.protocol.messages.PubRelMessage;
import com.test.protocol.messages.PublishMessage;
import com.test.protocol.messages.SubscribeMessage;
import com.test.protocol.messages.UnsubscribeMessage;
import com.test.server.ServerChannel;
import com.test.server.netty.NettyChannel;

public interface IProtocolProcessor {

	void processConnect(ServerChannel session, ConnectMessage msg);

	void processPubAck(ServerChannel session, PubAckMessage msg);

	void processPublish(ServerChannel session, PublishMessage msg);

	/**
	     * Intended usage is only for embedded versions of the broker, where the hosting application want to use the
	     * broker to send a publish message.
	     * Inspired by {@link #processPublish} but with some changes to avoid security check, and the handshake phases
	     * for Qos1 and Qos2.
	     * It also doesn't notifyTopicPublished because using internally the owner should already know where
	     * it's publishing.
	     * */

	void internalPublish(PublishMessage msg);

	/**
	 * Second phase of a publish QoS2 protocol, sent by publisher to the broker. Search the stored message and publish
	 * to all interested subscribers.
	 * */
	void processPubRel(ServerChannel session, PubRelMessage msg);

	void processPubRec(ServerChannel session, PubRecMessage msg);

	void processPubComp(ServerChannel session, PubCompMessage msg);

	void processDisconnect(ServerChannel session) throws InterruptedException;

	void processConnectionLost(String clientID, boolean sessionStolen, NettyChannel channel);

	/**
	 * Remove the clientID from topic subscription, if not previously subscribed,
	 * doesn't reply any error
	 */
	void processUnsubscribe(ServerChannel session, UnsubscribeMessage msg);

	void processSubscribe(ServerChannel session, SubscribeMessage msg);

}